<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
// namespace Org\Util;
use Think\Controller;
use Vendor;

/**
 * 前台公共控制器
 * 为防止多分组Controller名称冲突，公共Controller名称统一使用分组名称
 */
class LoanController extends Controller {

	//系统首页
    public function car(){
   
        $this->display();
    }

    public function house(){
      
        $this->display();
    }

    public function gjj(){
      
        $this->display();
    }

     public function zhd(){
      
        $this->display();
    }

    

    public function checkMobile(){
      
      $map['mobile'] = $_GET['mobile'];
      $flag =1;
      if(!empty($map['mobile'])){
          $data = M('loan')->where($map)->find();
          if(!empty($data['age'])){$flag = 0;}//
      }
      $return['flag'] = $flag;
      header('Content-Type:application/json; charset=utf-8');     
        exit(json_encode($return));

    }
    
    //预测贷款额度
    public function myloan(){
      $step = 1;
      $tpl = 'Loan/myloan';
      if(!empty($_POST)){
         if($_POST['step']==1){
            $map['username'] = I('username');
            $map['mobile']= I('mobile');
            $map['createtime']= time();
            $flag = M('loan')->add($map);
            if(!empty($flag)){
              $step = 2;
              $this->assign("mobile",$map['mobile']);
              $tpl = 'Loan/myloanTwo';
            }else{
              $tpl = 'Loan/error';
            }
            
            
         }else if($_POST['step']==2){
           $tpl =  $this->dataSave();
         }
      }

       $this->assign('step',$step);
       $this->display($tpl);
    }

     //保存数据，并推算贷款金额  (有车有房30-50万；有房无车20-50万;有车无房10-20万；)
    //房贷 houseLoan  车 car
     public function dataSave(){

       $data = $_POST;
       $loanMoney = 0 ;//预测贷款金额 
       unset($data['step']);
       $data['createtime'] = time();
       $flag = M('loan')->where('mobile='.$data['mobile'])->save($data);
       
       if(!empty($flag)){
       
       if($data['car']==1 && $data['houseLoan'] == 1){
         $loanMoney = "30-50";
       }else if($data['car']==0 && $data['houseLoan'] == 1){
         $loanMoney = "20-50";
       }else if($data['car']==1 && $data['houseLoan'] == 0){
         $loanMoney = "10-20";
       }
         $this->assign('loanMoney',$loanMoney);
        $tpl = 'Loan/myloanThr';
       }else{
         $tpl = 'Loan/error';
       }
     return $tpl;
       
        

     }


     public function myloanTwo(){
      // print_r($_POST);die();

       $this->display();
    }

     public function myloanThr(){
       $this->display();
    }
  
    //获取地理位置 暂时不做
    public function location(){

       define("TOKEN", "weixin");

       $wechatObj = new \Vendor\WechatCallbackapi();
      // $wechatObj->test();
       $wechatObj->responseMsg();

    }

}
